NOP, JMP, ACC = 0, 1, 2
TOKENS = {
    'nop' : NOP,
    'jmp' : JMP,
    'acc' : ACC
}

def run(code: list[(int,int)]) -> int:
    visited = set()
    pc, reg_val = 0, 0

    while pc not in visited and pc < len(code):
        visited.add(pc)
        (op, arg) = code[pc]
    
        if op == JMP:
            pc += arg
        elif op == ACC:
            reg_val += arg
            pc += 1
        elif op == NOP:
            pc += 1

    return reg_val

with open('input.txt') as file:
    code : list[(int,int)] = []
    for line in file.readlines():
        op, arg = line.split()
        code.append( (TOKENS[op], int(arg)) )
    
    print(run(code))